{extend name="public:_base" /}
{block name="css"}
<link rel="stylesheet" type="text/css" href="__STATIC__/admin/uploadify/uploadify.css">
{/block}
{block name="js"}
{load href="__STATIC__/admin/hui/lib/My97DatePicker/4.8/WdatePicker.js" /}
<script src="/tpl/static/artDialog/jquery.artDialog.js?skin=default"></script>
<script src="/tpl/static/artDialog/plugins/iframeTools.js"></script>
{load href="__STATIC__/admin/login/js/jquery-1.4.2.min.js" /}
{include file="public/_validform"}
<!--上传配置 -->
<script src="__STATIC__/admin/js/upfile.js" type="text/javascript"></script>

<!-- 配置文件 -->
<script type="text/javascript" src="__STATIC__/admin/hui/lib/ueditor/1.4.3/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="__STATIC__/admin/hui/lib/ueditor/1.4.3/ueditor.all.js"></script>

<script type="text/javascript">
    var ue = UE.getEditor('editor');
    $("[name='cid']").find("[value='{$data.cid ?? ''}']").attr("selected", true);
    upload_image('image','','300','300','500');
    var URL = {
            uploader: '{:url('Upload/image')}',
        swf:'__STATIC__/admin/uploadify/uploadify.swf',
        ROOT:'__PUBLIC__/uploads/image',
    }
    $(document).ready(function(e) {
        //dateformat(7);
        number();
        $("#submit_survey").click(function(){
            var cid = $('#contentid').val();
            var title = $('#questionnaire_til').val();
            if (title == '您可以在这里创建您的调研题目，同时对调研活动加以说明') {
                title = '';
            }
            if (title == '') {
                alert('请填写调研标题');
                return false;
            }
            save_survey();
            return false;
        });

        $(".del").live("click",function(){
            delimage($(this));
        });

        $(".optionul li .pic").live('mouseenter',function(){
            $(this).children("img").show();
        });

        $(".optionul li .pic").live('mouseleave',function(){
            $(this).children("img").hide();
        });

        /*投票截至时间*/
        $(".activity_list li .up_select").click(function(){
            $(this).children("div").show();
        });

        $(".activity_list li .up_select div").mouseleave(function(){
            $(this).hide();
        });

        $(".activity_list li .up_select div a").live("click",function(){
            var t = $(this).text();
            $(".activity_list li .up_select div").hide();
            $(".activity_list li .up_select u").text(t);
            $(".activity_list li .up_time").hide();
        });
    });

    function delimage(obj){
        obj.parent().addClass("hidden");
        obj.parent().prev("span").removeClass("hidden");
        obj.parent().parent().find("input[class='image_class']").val("");
    }
    function save_survey()
    {
        $.post("{:url('Research/saveInfo')}", $('#survey_form').serialize(), function(response){
            if (response.error_code) {
                alert(response.msg);
                return false;
            } else {
                location.href="{:url('Research/index')}";
                return false;
            }
        }, 'json');
    }

    function clear_form()
    {
        $("input").val('');
        $("textarea").val('');
        $("select").val('');
        $("#infotype").val(3);
        $("#tag_image_show").hide();
        $("#explanation").hide();
    }

    /*添加选项*/
    function number(){
        var i = 0;
        $(".optionul li").each(function(){
            $(this).find("input[name='userfile']").attr("id","userfile_" + i).live("change",function(){
                uploadimage($(this).attr("id"));
            });
            i ++;
        })
    }
    $(".orange_tips a.close").click(function(){
        $(".orange_tips").remove();
    })

    /*添加选项*/
    var a = new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
    function letters(){
        $(".question_box ul li").each(function(){
            $(this).find("span:first").html(a[$(this).index()]);
            $(this).find(".txt").attr('name', 'option['+$(this).parent().attr('id')+']['+$(this).index()+']');
            $(this).find(".hide_txt").attr('name', 'oid['+$(this).parent().attr('id')+']['+$(this).index()+']');
            $(this).find(".image_class").attr('name', 'image['+$(this).parent().attr('id')+']['+$(this).index()+']');
        });
        $(".topic_box .question_box").each(function(){
            $(this).find(".question_info span u").html($(this).index() + 1);
        });
        $('#question_info_1 .box_del').remove();
        $('.question_box ul li .txt').focus(function(){
            $(this).next().show();
        });

    }

    letters();

    $(".question_box ul li .list_del").live('click',function(){
        $(this).parents("li").remove();
        letters();
    });


    $(".question_box .bot_add a.btnGrayS").live('click',function(){
        var t = '<li><span>A</span><u>选项：</u><input type="hidden" class="hide_txt"> <input type="text" class="txt"/><input type="hidden" class="image_class" /> <a class="list_del" href="javascript:;" title="删除这个选项">×</a><span class="no_pic hidden"><a href="javascript:;" class="up"><i></i>插入图片<input type="file" name="userfile" title="图片建议尺寸：150*100" alt="图片建议尺寸：150*100"></a><div class="uppic_prompt">图片建议尺寸：<span>150*100</span><div class="caret_Up"><em>◆</em><span>◆</span></div></div></span><span class="pic hidden" style="width:auto"><a href="javascript:;">../fjdskjf.jpg</a><img src="" width="150" height="100"><a href="javascript:;" class="del">×</a></span></li>';
        if($(this).parents(".question_box").find("ul li").size() <= 25){
            $(this).parents(".question_box").find("ul").append(t);
            letters();
            number();
        }else{
            alert("您添加的数量够您用一辈子了！");
        }
    })
    /*添加选项结束*/

    /*添加题目和删除题目*/
    $(".add_questio a").click(function(){
        var t = '<div class="question_box"><p class="question_info"><span>问题<u>1</u>：</span><input type="text" class="txt" value="请填写问题的题目" />'
            +'<input type="checkbox" class="checkd" value="1" /><input type="hidden" class="hide_qid" id="qid[1]" name="qid[1]"><label> 允许多选</label><select class="typeselect"><option value="0">单选</option><option value="1">多选</option><option value="2">自由填写</option></select>&nbsp;&nbsp;<a href="javascript:;" class="box_del">删除</a></p>'
            +'<span class="insert_pic hidden">图片建议尺寸：150*100</span><ul id="1" class="optionul"><li><span>A</span><u>选项：</u><input type="hidden" class="hide_txt"> <input type="text" class="txt" /><input type="hidden" class="image_class" /> <a class="list_del" href="javascript:;" title="删除这个选项">×</a><span class="no_pic hidden"><a href="javascript:;" class="up"><i></i>插入图片<input type="file" name="userfile" title="图片建议尺寸：150*100" alt="图片建议尺寸：150*100"></a><div class="uppic_prompt">图片建议尺寸：<span>150*100</span><div class="caret_Up"><em>◆</em><span>◆</span></div></div></span><span class="pic hidden" style="width:auto"><a href="javascript:;">../fjdskjf.jpg</a><img src="" width="150" height="100"><a href="javascript:;" class="del">×</a></span></li>'
            +'<li><span>B</span><u>选项：</u><input type="hidden" class="hide_txt" > <input type="text" class="txt" /><input type="hidden" class="image_class" /> <a class="list_del" href="javascript:;" title="删除这个选项">×</a><span class="no_pic hidden"><a href="javascript:;" class="up"><i></i>插入图片<input type="file" name="userfile" title="图片建议尺寸：150*100" alt="图片建议尺寸：150*100"></a><div class="uppic_prompt">图片建议尺寸：<span>150*100</span><div class="caret_Up"><em>◆</em><span>◆</span></div></div></span><span class="pic hidden" style="width:auto"><a href="javascript:;">../fjdskjf.jpg</a><img src="" width="150" height="100"><a href="javascript:;" class="del">×</a></span></li>'
            +'<li><span>C</span><u>选项：</u><input type="hidden" class="hide_txt" > <input type="text" class="txt" /><input type="hidden" class="image_class" /> <a class="list_del" href="javascript:;" title="删除这个选项">×</a><span class="no_pic hidden"><a href="javascript:;" class="up"><i></i>插入图片<input type="file" name="userfile" title="图片建议尺寸：150*100" alt="图片建议尺寸：150*100"></a><div class="uppic_prompt">图片建议尺寸：<span>150*100</span><div class="caret_Up"><em>◆</em><span>◆</span></div></div></span><span class="pic hidden" style="width:auto"><a href="javascript:;">../fjdskjf.jpg</a><img src="" width="150" height="100"><a href="javascript:;" class="del">×</a></span></li>'
            +'</ul><p class="bot_add"><a href="javascript:;" class="btnGrayS vm bigbtn"><img src="/images/product/add.png" width="16" class="vm">再添加一个选项</a></p></div>';
        $(".add_questio").before(t);
        $(".question_box:last").find("li:eq(2)").nextAll().remove();
        $(".question_box").each(function() {
            //$(this).find("u").html($(this).index());
            $(this).find(".question_info .txt").attr('name', 'question['+$(this).index()+']');
//            $(this).find(".question_info .checkd").attr('name', 'ismulti['+$(this).index()+']');
            $(this).find(".question_info .typeselect").attr('name', 'ismulti['+$(this).index()+']');

            $(this).find(".question_info .checkd").attr('id', 'ismulti_'+$(this).index());
            $(this).find(".question_info label").attr('for', 'ismulti_'+$(this).index());
            $(this).find(".question_info .hide_qid").attr('name', 'qid['+$(this).index()+']');
            $(this).find("ul").attr('id', $(this).index());
        });
        letters();
        number();
    })
    $(".box_del").live('click',function(){
        $(this).parents(".question_box").remove();
        $(".question_box").each(function() {
            //$(this).find("u").html($(this).index());
        });
        letters();
        number();
    })
    /*添加题目和删除题目结束*/

    /*input默认文字显示、消失*/
    $("#questionnaire_til").focusin(function(){
        if($(this).val() == "您可以在这里创建您的调研题目，同时对调研活动加以说明"){
            $(this).val("");
            $(this).css("color","#666");
        }
    }).focusout(function(){
        if($(this).val() == ""){
            $(this).val("您可以在这里创建您的调研题目，同时对调研活动加以说明");
            $(this).css("color","#999");
        }
    })
    $(".question_box p .txt").live('focusin',function(){
        if($(this).val() == "请填写问题的题目"){
            $(this).val("");
            $(this).css("color","#666");
        }
    }).live('focusout',function(){
        if($(this).val() == ""){
            $(this).val("请填写问题的题目");
            $(this).css("color","#999");
        }
    });


    function dateformat(day){
        var date = new Date();
        date.setDate(date.getDate()+day);
        var deadline = date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()+' '+date.getHours()+':'+date.getMinutes()+':'+date.getSeconds();
        $("#deadline").val(deadline);
    }
</script>
{/block}
{block name="main"}
<div class="page-container">

    <form class="form form-horizontal" action="{:url(\''.\\think\\Request::instance()->controller().'/save')}" id="form" method="post">
        <ul class="activity_list">
            <li>
                调研标题：
                <input type="text" class="txt" id="questionnaire_til" name="title" value="{$data.title ?? ''}" placeholder="您可以在这里创建您的调研题目，同时对调研活动加以说明">
            </li>
            <li>
                　关键词：
                <input type="text" class="txt" id="keyword" name="keyword" value="{$data.keyword ?? ''}">
            </li>
            <li id="explanation" style="display: list-item;">
                调研说明：
                <p>
                    <script id="editor" type="text/plain" name="description" style="width:100%;height:400px;">{$data.description|default=''|html_entity_decode ?? ''}</script>

                    </p>
                    </li>
                    <li>
                    开始时间：
                    <span class="up_time" style="width:150px;">
                        <u id="t">
                        <input type="text" value="{$data['starttime']}" id="starttime" style="margin-top:6px;width:125px;border:0px;" name="starttime" class="hasDatepicker" onClick="WdatePicker({dateFmt:'yyyy-MM-dd  HH:mm:ss'})">
                        </u>
                        </span>
                        </li>
                        <li>
                        截至时间：
                    <span class="up_time" style="width:150px;">
                        <u id="t">
                        <input type="text" value="{$data['dateline']}" id="deadline" style="margin-top:6px;width:125px;border:0px;" name="dateline" class="hasDatepicker" onClick="WdatePicker({dateFmt:'yyyy-MM-dd  HH:mm:ss'})">
                        </u>
                        </span>
                        </li>
                        </ul>
                        <div class="topic_box">
                        {volist name="list" id="ques" key="i"}
                        <div class="question_box" id="question_info_{$i}">
                        <p class="question_info">
                        <span>问题<u>{$i}</u>：</span>
                    <input type="text" class="txt" name="question[{$i}]" value="{$ques['name']}">
                    <input type="text" class="txt" name="answer[{$i}]" value="{$ques['answer']}">
                        <input type="checkbox" class="checkd" name="ismulti[{$i}]" id="ismulti_{$i}" value="1" {if condition="$ques['type'] eq 1"}checked{/if} >
                    <input type="hidden" class="hide_qid" name="qid[{$i}]" id="qid[{$i}]" value="{$ques['id']}">
                        <label for="ismulti_{$i}"> 允许多选{$ques['type']}</label><select name="ismulti[{$i}]" class="typeselect"><option value="0" {if condition="$ques['type'] eq 0"}selected{/if}>单选</option><option value="1" {if condition="$ques['type'] eq 1"}selected{/if}>多选</option><option value="2" {if condition="$ques['type'] eq 2"}selected{/if}>自由填写</option></select>{if condition="$i neq 1"}&nbsp;&nbsp;<a href="javascript:;" class="box_del">删除</a>{/if}
                    </p>
                        <ul id="{$i}" class="optionul">
                            {volist name="ques['Ranswer']" id="answer" key="k"}
                            <li>
                            <span>A</span><u>选项：</u>
                        <input type="hidden" class="hide_txt" name="oid[{$i}][{$k}]" value="{$answer['id']}">
                            <input type="text" class="txt" name="option[{$i}][{$k}]" value="{$answer['name']}">
                            <a class="list_del" href="javascript:;" title="删除这个选项">×</a>
                        </li>
                        {/volist}
                    </ul>
                        <p class="bot_add"><a href="javascript:;" class="btnGrayS vm bigbtn"><img src="/images/product/add.png" width="16" class="vm">再添加一个选项</a></p>
                            </div>
                            {/volist}
                    <p class="add_questio"><a href="javascript:;" title="添加" class="btnGrayS vm bigbtn"><img src="/images/product/add.png" width="16" class="vm">再添加一题</a></p>
                            </div>

                            <ul>
                            <ul class="pub_list">
                            <li class="bot">
                            <input name="id" value="{$data.id ?? ''}"  type="hidden" />
                            <input type="hidden" value="{$data.cid ?? $addcid}" name="cidold" />
                            {:token()}
                        <input class="btn radius btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                        <input class="btn radius btn-default radius" type="reset" value="&nbsp;&nbsp;重置&nbsp;&nbsp;">
                        <!-- <button onClick="layer_close();" class="btn radius btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button> -->

                        </li>
                        </ul>
                        </ul>

                        </form>

                        </div>

                        {/block}